package com.api.sw.duban.action;

import com.alibaba.fastjson.JSONObject;
import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.api.sw.duban.model.Uf_bqk;
import com.api.sw.duban.service.BqkBaseService;
import com.api.sw.duban.util.*;
import com.cloudstore.eccom.constant.WeaBoolAttr;
import com.cloudstore.eccom.pc.table.*;
import com.cloudstore.eccom.result.WeaResultMsg;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import weaver.conn.RecordSet;
import weaver.general.PageIdConst;
import weaver.general.Util;
import weaver.hrm.User;

import java.text.SimpleDateFormat;
import java.util.*;

/*
    决策督查 action
 */
public class DubanJcAction {
    private final static LogTool log = new LogTool("/log/duban/",false);
    public DubanJcAction(){

    };
    //查询条件  文号 标题 编号
    public Map<String, Object> getTablelist(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            if(params!=null){
                log.writeLog(params.toString());
            }
            //SUBSTR(modedatacreatedate,0,4)
            String currentUserid=user.getUID()+"";
            String tzid=(String)Util.null2String(params.get("tzid")) ;//通知ID
            String nd=(String)Util.null2String(params.get("nd")) ;//年度
            String gzrw=(String)Util.null2String(params.get("gzrw")) ;//任务内容
            String qtdw=(String)Util.null2String(params.get("qtdw")) ;//牵头单位
            String tzbt=(String)Util.null2String(params.get("tzbt")) ;//通知标题
            String zt=(String)Util.null2String(params.get("zt")) ;//状态
            //日期
            String fksx=(String)Util.null2String(params.get("fksx")) ;//反馈时限
            String fksxfrom=(String)Util.null2String(params.get("fksxfrom")) ;//反馈时限from
            String fksxto=(String)Util.null2String(params.get("fksxto")) ;//反馈时限to


            //1 今天:2本周:3本月:4本季度:5本年:6时间区间:7上年:8:上个月

            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f79285711131";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());
            //只是查看  当前人员自己的 督查关联任务

            //String sqlwhere =" 1=1 a.id='"+tzid+"' and a.ssdctz=b.id ";
            String sqlwhere ="";
            if(!"".equals(tzid)){
                sqlwhere =" 1=1  and a.ssdctz='"+tzid+"' and a.sfsrw=0 and a.ssdctz=b.id and a.modedatacreater="+user.getUID();
            }else{
                sqlwhere =" 1=1  and a.sfsrw=0 and a.ssdctz=b.id and a.modedatacreater="+user.getUID();

            }

            if("sqlserver".equals(DBType)){
                //sqlwhere=" 1=1  and a.id in (select ssrwid from uf_dbjblb b where (','+cast(b.djr as varchar(4000))+',' like '%,"+user.getUID()+",%' or b.dbry='"+user.getUID()+"') and isnull(b.zt,-1) in (2)) ";
            }else{
                //sqlwhere=" 1=1   and a.id in (select ssrwid from uf_dbjblb b where (','||to_char(substr(b.djr,1,1000))||',' like '%,"+user.getUID()+",%' or b.dbry='"+user.getUID()+"') and isnull(b.zt,-1) in (2)) ";
            }

            if(!"".equals(nd)){
                sqlwhere=sqlwhere+" and SUBSTR(a.modedatacreatedate,0,4)='"+nd+"'";
            }
            if(!"".equals(gzrw)){
                sqlwhere=sqlwhere+" and a.gzrw like '%"+gzrw+"%'";
            }

            if(!"".equals(qtdw)){
                if(qtdw.endsWith(",")){
                    qtdw=qtdw.substring(0,qtdw.length()-1);
                }
                //uf_dcsxzb where substr(jbsj,0,10)>'2020-10-13'
                if("sqlserver".equals(DBType)){
                    sqlwhere=" and ','+cast(a.qtdw as varchar(4000))+',' like '%,"+qtdw+",%'  ";
                }else{
                    sqlwhere=" and ','||to_char(substr(a.qtdw,1,1000))||',' like '%,"+qtdw+",%'  ";
                }
            }
            if(!"".equals(tzbt)){
                sqlwhere=sqlwhere+" and b.bt like '%"+tzbt+"%'";
            }
            if(!"".equals(zt)){
                sqlwhere=sqlwhere+" and a.zt='"+zt+"'";
            }
            //substr(xsfk,0,10)

            if(!"".equals(fksx)&&!"0".equals(fksx)) {
                String newsqlwhere=" 1=1 and ";
                if ("6".equals(fksx)) {
                    String fksql = "select * from uf_jcdclsfkjl where ";
                    if ("sqlserver".equals(DBType)) {

                    } else {
                        if (!"".equals(fksxfrom) && !"".equals(fksxto)) {
                            newsqlwhere = newsqlwhere + " substr(fmodedatacreatedate,0,10)>'" + fksxfrom + "' and substr(fmodedatacreatedate,0,10)<'" + fksxto + "'";
                        } else {
                            if (!"".equals(fksxfrom)) {
                                newsqlwhere = newsqlwhere + " substr(fmodedatacreatedate,0,10)>'" + fksxfrom + "'";
                            }
                            if (!"".equals(fksxto)) {
                                newsqlwhere = newsqlwhere + " substr(fmodedatacreatedate,0,10)<'" + fksxto + "'";
                            }
                        }

                    }
                } else {
                    if ("sqlserver".equals(DBType)) {
                        newsqlwhere = newsqlwhere + DubUtil.getRQfW(fksx, "substr(fmodedatacreatedate,0,10)");
                    } else {
                        newsqlwhere = newsqlwhere + DubUtil.getRQfW(fksx, "substr(fmodedatacreatedate,0,10)");
                    }
                }
                if(!"".equals(newsqlwhere)){
                    sqlwhere=sqlwhere+" and a.id in (select f.fkrwid from uf_jcdclsfkjl f where f.ssdctz='"+tzid+"' and "+newsqlwhere+")";
                }
            }

            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);


            String fileds = " a.*,b.lb jcdctzlb,'uf_jcdctz' tablename,'lb' lbfield,'uf_jcdcrw' zttable,'zt' ztfield,b.bt ssdctztext,b.id dctzid ";
            table.setBackfields(fileds);

            table.setSqlform("uf_jcdcrw a,uf_jcdctz b ");
            table.setSqlwhere(sqlwhere);
            table.setSqlorderby("dctzid,id desc");
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");


            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显
            table.getColumns().add(new WeaTableColumn("10%", "编号", "bh","bh"));
            WeaTableColumn sxlb=new WeaTableColumn("10%", "事项类别", "jcdctzlb","jcdctzlb","com.api.sw.duban.util.dubanTran.getSelectnameByValue");
            sxlb.setOtherpara("column:tablename").setOtherpara2("column:lbfield");
            table.getColumns().add(sxlb);
            table.getColumns().add(new WeaTableColumn("50%", "工作任务", "gzrw","gzrw"));
            WeaTableColumn zt1=new WeaTableColumn("10%", "状态", "zt","zt","com.api.sw.duban.util.dubanTran.getSelectnameByValue");
            zt1.setOtherpara("column:zttable").setOtherpara2("column:ztfield");
            table.getColumns().add(zt1);
            //所属通知
            //table.getColumns().add(new WeaTableColumn("20%", "所属通知", "ssdctztext","ssdctztext"));
            if("".equals(tzid)){
                table.getColumns().add(new WeaTableColumn("20%", "所属通知", "ssdctztext","ssdctztext"));
            }else{
                table.getColumns().add(new WeaTableColumn("20%", "标签", "rwbq","rwbq","com.api.sw.duban.util.dubanTran.getBqk"));
            }

            table.getColumns().add(new WeaTableColumn("20%", "通知ID", "ssdctz","ssdctz").setDisplay(WeaBoolAttr.FALSE));
            table.getColumns().add(new WeaTableColumn("10%", "牵头单位", "qtdw","qtdw","com.api.sw.duban.util.dubanTran.getSwDpartmentnameByid"));
            table.getColumns().add(new WeaTableColumn("10%", "操作", "opter","opter"));


            //增加右侧操作选项
            WeaTableOperates weaTableOperates = new WeaTableOperates();
            List<WeaTableOperate> operateList = new ArrayList<>();

            WeaTableOperate query = new WeaTableOperate("查看","","0");
            WeaTableOperate qs = new WeaTableOperate("签收","","1");

            operateList.add(query);
            operateList.add(qs);

            //设置check是否可用
            //设置check是否可用
            List<WeaTableCheckboxpopedom> checkboxpopedomList = new ArrayList<WeaTableCheckboxpopedom>();
            WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom();
            checkboxpopedom.setShowmethod("com.api.sw.duban.util.dubanTran.disabledCheckbox");//勾选标识显示方法，允许勾选返回true,不允许勾选返回false
            checkboxpopedom.setPopedompara("column:id");//传入参数
            checkboxpopedomList.add(checkboxpopedom);

            table.setOperates(weaTableOperates);//增加操作
            table.setCheckboxList(checkboxpopedomList);





            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    public Map<String, Object> getCondition(Map<String,Object> params, User user) {
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
        String currentNy=sim.format(new Date()).split("-")[0];
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //角色判断参考代码
//        if(!HrmUserVarify.checkUserRight("LogView:View", user)){
//            apidatas.put("hasRight", false);
//            return apidatas;
//        }

        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }

        apidatas.put("hasRight", true);

        /**
         * 高级搜索条件
         */
        ConditionFactory conditionFactory = new ConditionFactory(user);

        //条件组
        List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>();

        List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();

        //文本输入框
        SearchConditionItem wh = conditionFactory.createCondition(ConditionType.INPUT,502327, "nd");
        wh.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        wh.setValue(currentNy);
        wh.setFieldcol(16);	//条件输入框所占宽度，默认值18
        wh.setLabelcol(8);
        wh.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        wh.setLabel("年度"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(wh);


        //文本输入框
        SearchConditionItem bh = conditionFactory.createCondition(ConditionType.INPUT,502327, "gzrw");
        bh.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        bh.setFieldcol(16);	//条件输入框所占宽度，默认值18
        bh.setLabelcol(8);
        bh.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        bh.setLabel("任务名称"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(bh);

        //通知标题
        SearchConditionItem tzbt = conditionFactory.createCondition(ConditionType.INPUT,502327, "tzbt");
        tzbt.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        tzbt.setFieldcol(16);	//条件输入框所占宽度，默认值18
        tzbt.setLabelcol(8);
        tzbt.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        tzbt.setLabel("通知标题"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(tzbt);

        //主办单位
        SearchConditionItem zbdw = conditionFactory.createCondition(ConditionType.BROWSER,502327, "qtdw","142");
        zbdw.setLabel("牵头单位");
        conditionItems.add(zbdw);
        //反馈时限
        SearchConditionItem fksx = conditionFactory.createCondition(ConditionType.DATE,502327, new String[]{"fksx", "fksxfrom", "fksxto"});
        fksx.setLabel("反馈时间");
        conditionItems.add(fksx);

        //状态
        SearchConditionItem zt = conditionFactory.createCondition(ConditionType.SELECT,502327,"zt");
        List<SearchConditionOption> typeOptions = new ArrayList <SearchConditionOption>();  //设置选项值
        typeOptions.add(new SearchConditionOption("","全部"));
        typeOptions.add(new SearchConditionOption("0","登记"));
        typeOptions.add(new SearchConditionOption("1","办理中"));
        typeOptions.add(new SearchConditionOption("2","已办结"));
        typeOptions.add(new SearchConditionOption("3","反馈中"));
        typeOptions.add(new SearchConditionOption("4","已移除"));
        zt.setOptions(typeOptions);
        zt.setLabel("状态");
        conditionItems.add(zt);



        addGroups.add(new SearchConditionGroup("查询条件",true,conditionItems));


        apidatas.put("condition",addGroups);

        return apidatas;

    }
    //查询条件  文号 标题 编号 jcstatus  0:tz 1:已办结
    public Map<String, Object> getTablelistZt(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            if(params!=null){
                log.writeLog(params.toString());
            }
            //SUBSTR(modedatacreatedate,0,4)
            String jcstatus=(String)Util.null2String(params.get("jcstatus")) ;//查询类型 0，1
            String dcr=(String)Util.null2String(params.get("dcr")) ;//都察人
            String nd=(String)Util.null2String(params.get("nd")) ;//年度
            String tzbt=(String)Util.null2String(params.get("tzbt")) ;//通知标题

            String lb=(String)Util.null2String(params.get("lb")) ;//类别
            String wh=(String)Util.null2String(params.get("wh")) ;//问号




            //1 今天:2本周:3本月:4本季度:5本年:6时间区间:7上年:8:上个月

            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f792857111311";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());
            String sqlwhere =" 1=1  ";
            //String sqlwhere =" 1=1 a.id='"+tzid+"' and a.ssdctz=b.id ";
            if("1".equals(jcstatus)){//已办结
                //sqlwhere=sqlwhere+" and (a.zt=2 or ( not EXIST  (select 1 from uf_jcdcrw b where b.ssdctz=a.id and isnull(b.zt,-1) in (-1,0,1) and a.zt=1))  ";
                sqlwhere=sqlwhere+"   and (a.zt=2 or (not exists (select * from uf_jcdcrw b where b.ssdctz=a.id and isnull(b.zt,-1) in (-1,0,1) )) and a.id in (select distinct b1.ssdctz from uf_jcdcrw b1 where b1.ssdctz=a.id ) )    ";
            }


            if("sqlserver".equals(DBType)){
                //sqlwhere=" 1=1  and a.id in (select ssrwid from uf_dbjblb b where (','+cast(b.djr as varchar(4000))+',' like '%,"+user.getUID()+",%' or b.dbry='"+user.getUID()+"') and isnull(b.zt,-1) in (2)) ";
            }else{
                //sqlwhere=" 1=1   and a.id in (select ssrwid from uf_dbjblb b where (','||to_char(substr(b.djr,1,1000))||',' like '%,"+user.getUID()+",%' or b.dbry='"+user.getUID()+"') and isnull(b.zt,-1) in (2)) ";
            }

            if(!"".equals(nd)){
                sqlwhere=sqlwhere+" and SUBSTR(a.modedatacreatedate,0,4)='"+nd+"'";
            }



            if(!"".equals(tzbt)){
                sqlwhere=sqlwhere+" and b.bt like '%"+tzbt+"%'";
            }
            if(!"".equals(lb)){
                sqlwhere=sqlwhere+" and a.lb='"+lb+"'";
            }
            if(!"".equals(dcr)){
                sqlwhere=sqlwhere+" and a.modedatacreater='"+dcr+"'";
            }
            if(!"".equals(wh)){
                sqlwhere=sqlwhere+" and a.dcwh='"+wh+"'";
            }
            //substr(xsfk,0,10)



            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            //table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);


            String fileds = " a.*,a.lb jcdctzlb,'uf_jcdctz' tablename,'lb' lbfield,'uf_jcdcrw' zttable,'zt' ztfield ";
            table.setBackfields(fileds);

            table.setSqlform("uf_jcdctz a ");
            table.setSqlwhere(sqlwhere);
            table.setSqlorderby("id");
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");


            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显
            table.getColumns().add(new WeaTableColumn("10%", "文号", "dcwh","dcwh"));
            table.getColumns().add(new WeaTableColumn("30%", "标题", "id","id","com.api.sw.duban.util.dubanTran.getDubanTitleJTz"));
            WeaTableColumn sxlb=new WeaTableColumn("10%", "事项类别", "jcdctzlb","jcdctzlb","com.api.sw.duban.util.dubanTran.getSelectnameByValue");
            sxlb.setOtherpara("column:tablename").setOtherpara2("column:lbfield");
            table.getColumns().add(sxlb);
            //所属通知
            table.getColumns().add(new WeaTableColumn("20%", "反馈时限", "fksx","fksx"));
            table.getColumns().add(new WeaTableColumn("10%", "交办时间", "jbsj","jbsj"));
            if(!"1".equals(jcstatus)) {//已办结) 设置导出任务按钮
                WeaTableColumn zt1=new WeaTableColumn("10%", "状态", "zt","zt","com.api.sw.duban.util.dubanTran.getSelectnameByValue");
                zt1.setOtherpara("column:zttable").setOtherpara2("column:ztfield");
                table.getColumns().add(zt1);
            }
            table.getColumns().add(new WeaTableColumn("10%", "办结时间", "bjsj","bjsj"));
            table.getColumns().add(new WeaTableColumn("10%", "是否是计划", "sffkjh","sffkjh").setDisplay(WeaBoolAttr.FALSE));
            if("1".equals(jcstatus)){//已办结) 设置导出任务按钮
                table.getColumns().add(new WeaTableColumn("10%", "操作", "opter","opt"));
            }else{//台账不需要

            }



            //增加右侧操作选项
            WeaTableOperates weaTableOperates = new WeaTableOperates();
            List<WeaTableOperate> operateList = new ArrayList<>();

            WeaTableOperate query = new WeaTableOperate("查看","","0");
            WeaTableOperate qs = new WeaTableOperate("签收","","1");

            operateList.add(query);
            operateList.add(qs);

            //设置check是否可用
            //设置check是否可用
            List<WeaTableCheckboxpopedom> checkboxpopedomList = new ArrayList<WeaTableCheckboxpopedom>();
            WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom();
            checkboxpopedom.setShowmethod("com.api.sw.duban.util.dubanTran.disabledCheckbox");//勾选标识显示方法，允许勾选返回true,不允许勾选返回false
            checkboxpopedom.setPopedompara("column:id");//传入参数
            checkboxpopedomList.add(checkboxpopedom);
            table.setCheckboxList(checkboxpopedomList);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    /*
        台账以及 已办结  更具  jcstatus  0:tz 1:已办结
     */
    public Map<String, Object> getConditionTz(Map<String,Object> params, User user) {
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
        String currentNy=sim.format(new Date()).split("-")[0];
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //角色判断参考代码
//        if(!HrmUserVarify.checkUserRight("LogView:View", user)){
//            apidatas.put("hasRight", false);
//            return apidatas;
//        }

        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }

        apidatas.put("hasRight", true);

        /**
         * 高级搜索条件
         */
        ConditionFactory conditionFactory = new ConditionFactory(user);

        //条件组
        List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>();

        List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();

        //文本输入框
        SearchConditionItem nd = conditionFactory.createCondition(ConditionType.INPUT,502327, "nd");
        nd.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        nd.setValue(currentNy);
        nd.setFieldcol(16);	//条件输入框所占宽度，默认值18
        nd.setLabelcol(8);
        nd.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        nd.setLabel("年度"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(nd);
        //文本输入框
        SearchConditionItem wh = conditionFactory.createCondition(ConditionType.INPUT,502327, "wh");
        wh.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        wh.setFieldcol(16);	//条件输入框所占宽度，默认值18
        wh.setLabelcol(8);
        wh.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        wh.setLabel("文号"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(wh);
        //通知标题
        SearchConditionItem tzbt = conditionFactory.createCondition(ConditionType.INPUT,502327, "tzbt");
        tzbt.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        tzbt.setFieldcol(16);	//条件输入框所占宽度，默认值18
        tzbt.setLabelcol(8);
        tzbt.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        tzbt.setLabel("通知标题"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(tzbt);
        //主办单位
        SearchConditionItem zbdw = conditionFactory.createCondition(ConditionType.BROWSER,502327, "dcr","1");
        zbdw.setLabel("督察人");
        conditionItems.add(zbdw);
        //类别
        SearchConditionItem zt = conditionFactory.createCondition(ConditionType.SELECT,502327,"lb");
        //zt.setOptions(DubUtil.getSelectnameByValue("uf_jcdctz","lb"));
        List<SearchConditionOption> typeOptions = new ArrayList <SearchConditionOption>();  //设置选项值
        typeOptions.add(new SearchConditionOption("","全部"));
        typeOptions.add(new SearchConditionOption("0","领导批示"));
        typeOptions.add(new SearchConditionOption("1","全会重点任务"));
        typeOptions.add(new SearchConditionOption("2","常委会议定事项"));
        zt.setOptions(typeOptions);
        zt.setLabel("类别");
        conditionItems.add(zt);


        addGroups.add(new SearchConditionGroup("查询条件",true,conditionItems));


        apidatas.put("condition",addGroups);

        return apidatas;

    }

    public Map<String, Object> getSubmitCondition(Map<String,Object> params, User user) {
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
        String currentNy=sim.format(new Date()).split("-")[0];
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //角色判断参考代码
//        if(!HrmUserVarify.checkUserRight("LogView:View", user)){
//            apidatas.put("hasRight", false);
//            return apidatas;
//        }

        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }

        apidatas.put("hasRight", true);

        /**
         * 高级搜索条件
         */
        ConditionFactory conditionFactory = new ConditionFactory(user);

        //条件组
        List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>();

        List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();
        //主办单位
        SearchConditionItem zbdw = conditionFactory.createCondition(ConditionType.BROWSER,502327, "qtdw","142");
        zbdw.setLabel("牵头单位");
        zbdw.setViewAttr(3);
        zbdw.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        zbdw.setFieldcol(13);	//条件输入框所占宽度，默认值18
        zbdw.setLabelcol(8);
        
        conditionItems.add(zbdw);

        addGroups.add(new SearchConditionGroup("设置",true,conditionItems));


        apidatas.put("condition",addGroups);

        return apidatas;

    }
    public Map<String, Object> gettzrw(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{

        String tzid=(String)Util.null2String(params.get("tzid")) ;//通知ID
        String gzrw=(String)Util.null2String(params.get("gzrw")) ;//工作内容
        //获取通知的 类型以及  级别的拼
        WeaResultMsg result = new WeaResultMsg(false);
        RecordSet re=new RecordSet();
        String lb="-1";//类型
        String check="-1";//检查对象
        String sql="select lb,check1||'-'||check2||'-'||check3||'-'||check4 checktype from uf_jcdctz a,uf_jcgzsd b where a.id=b.ssdctz and a.id="+tzid;
        re.execute(sql);
        if(re.next()){
            lb=Util.null2String(re.getString("lb"));
            check=Util.null2String(re.getString("checktype"));
        }

        //返回消息结构体
        String DBType=re.getDBType();
        //log.writeLog("DBType"+DBType);
        String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f792857111311";
        String pageUid = pageID + "_" + user.getUID();
        String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

        String sqlwhere ="";


        if("sqlserver".equals(DBType)){
            sqlwhere=" 1=1 and a.id=b.ssdctz and a.lb='"+lb+"' and a.id=d.ssdctz and  d.check1||'-'||d.check2||'-'||d.check3||'-'||d.check4='"+check+"' " +
                    "and b.sfsrw=0 and b.zt in (0,1,2,3) ";
        }else{
            sqlwhere=" 1=1 and  a.id=b.ssdctz and a.lb='"+lb+"' and a.id=d.ssdctz and  d.check1||'-'||d.check2||'-'||d.check3||'-'||d.check4='"+check+"' " +
                     " and b.sfsrw=0 and b.zt in (0,1,2,3) ";
        }
        if(!"".equals(gzrw)){
            sqlwhere=sqlwhere+" and b.gzrw like '%"+gzrw+"%'";
        }


        log.writeLog(sqlwhere);
        //新建一个weatable
        WeaTable table = new WeaTable();
        table.setTableType(WeaTableType.CHECKBOX);
        table.setPageUID(pageUid);
        table.setPageID(pageID);
        table.setPagesize(pageSize);


        String fileds = " b.*,b.lb jcdctzlb,'uf_jcdctz' tablename,'lb' lbfield,'uf_jcdcrw' zttable,'zt' ztfield ";
        table.setBackfields(fileds);

        table.setSqlform("uf_jcdctz a,uf_jcdcrw b,uf_jcgzsd d  ");
        table.setSqlwhere(sqlwhere);
        table.setSqlorderby(" id desc");
        table.setSqlprimarykey("id");
        table.setSqlisdistinct("false");


        table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显
        table.getColumns().add(new WeaTableColumn("10%", "编号", "bh","bh"));
        WeaTableColumn sxlb=new WeaTableColumn("10%", "事项类别", "lb","lb","com.api.sw.duban.util.dubanTran.getSelectnameByValue");
        sxlb.setOtherpara("column:tablename").setOtherpara2("column:lbfield");
        table.getColumns().add(sxlb);
        table.getColumns().add(new WeaTableColumn("50%", "工作任务", "gzrw","gzrw"));
        WeaTableColumn zt1=new WeaTableColumn("10%", "状态", "zt","zt","com.api.sw.duban.util.dubanTran.getSelectnameByValue");
        zt1.setOtherpara("column:zttable").setOtherpara2("column:ztfield");
        table.getColumns().add(zt1);
        //所属通知
        table.getColumns().add(new WeaTableColumn("10%", "牵头单位", "qtdw","qtdw","com.api.sw.duban.util.dubanTran.getSwDpartmentnameByid"));



        //增加右侧操作选项
        WeaTableOperates weaTableOperates = new WeaTableOperates();
        List<WeaTableOperate> operateList = new ArrayList<>();

        WeaTableOperate query = new WeaTableOperate("查看","","0");
        WeaTableOperate qs = new WeaTableOperate("签收","","1");

        operateList.add(query);
        operateList.add(qs);

        //设置check是否可用
        //设置check是否可用

        table.setOperates(weaTableOperates);//增加操作
        result.putAll(table.makeDataResult());
        result.put("hasRight", true);
        result.success();
        apidatas = result.getResultMap();

    } catch (Exception e) {
        e.printStackTrace();
    }
        return apidatas;
    }
    public Map<String, Object> getrwCondition(Map<String,Object> params, User user) {
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
        String currentNy=sim.format(new Date()).split("-")[0];
        Map<String, Object> apidatas = new HashMap<String, Object>();
        //角色判断参考代码
//        if(!HrmUserVarify.checkUserRight("LogView:View", user)){
//            apidatas.put("hasRight", false);
//            return apidatas;
//        }

        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }

        apidatas.put("hasRight", true);

        /**
         * 高级搜索条件
         */
        ConditionFactory conditionFactory = new ConditionFactory(user);

        //条件组
        List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>();

        List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();
        //工作任务
        SearchConditionItem wh = conditionFactory.createCondition(ConditionType.INPUT,502327, "gzrw");
        wh.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        wh.setFieldcol(16);	//条件输入框所占宽度，默认值18
        wh.setLabelcol(8);
        wh.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        wh.setLabel("工作任务"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(wh);

        addGroups.add(new SearchConditionGroup("任务",true,conditionItems));
        apidatas.put("condition",addGroups);

        return apidatas;

    }
    public Map<String, Object> saveBqk(Map<String,Object> params, User user){
        RecordSet re=new RecordSet();
        boolean flag=true;
        String mess="";
        Map<String, Object> apidatas = new HashMap<String, Object>();
        List<Object> list=new ArrayList<Object>();
        String mc=Util.null2String(params.get("mc")).trim() ;//名称
        String wzys=Util.null2String(params.get("wzys")) ;//文字颜色
        String bjys=Util.null2String(params.get("bjys")) ;//	背景颜色
        String bqys=Util.null2String(params.get("bqys")) ;//标签颜色
        String mkid=Util.null2String(params.get("mkid")) ;//模块ID
        log.writeLog("mc--->"+mc);
        log.writeLog("wzys--->"+wzys);
        log.writeLog("bjys--->"+bjys);
        log.writeLog("bqys--->"+bqys);
        log.writeLog("mkid--->"+mkid);
        //检验是否存在
        Uf_bqk uf_bqk=new Uf_bqk();
        String sql="select * from uf_bqk where mc='"+mc+"'";
        re.execute(sql);
        if(!re.next()){
            uf_bqk.setMc(mc);
            uf_bqk.setWzys(wzys);
            uf_bqk.setBjys(bjys);
            uf_bqk.setBqys(bqys);
            uf_bqk.setMkid(mkid);
            uf_bqk.setModedatacreater(user.getUID()+"");
            list.add(uf_bqk);
            //写入
            BqkBaseService BqkBaseService=new BqkBaseService();
            mess=BqkBaseService.getObjMapList(list,null);
            if(!"".equals(mess)){
                flag=false;
            }
        }
        apidatas.put("flag",true);
        apidatas.put("mess",mess);
        return apidatas;
    }
    public Map<String, Object> saveRwBqk(Map<String,Object> params, User user){
        RecordSet re=new RecordSet();
        boolean flag=true;
        String mess="";
        Map<String, Object> apidatas = new HashMap<String, Object>();
        List<Object> list=new ArrayList<Object>();
        String bqid=Util.null2String(params.get("bqid")).trim() ;//标签ID
        String rwid=Util.null2String(params.get("rwid")) ;//任务ID
        if(rwid.endsWith(",")){
            rwid=rwid.substring(0,rwid.length()-1);
        }
        log.writeLog("bqid--->"+bqid);
        log.writeLog("rwid--->"+rwid);

        //检验是否存在
        Uf_bqk uf_bqk=new Uf_bqk();
        if(!"".equals(rwid)&&!"".equals(bqid)){
            String sql="update uf_jcdcrw set rwbq='"+bqid+"' where id in ("+rwid+")";
            re.execute(sql);
        }

        apidatas.put("flag",true);
        apidatas.put("mess",mess);
        return apidatas;
    }
    //清除标签
    public Map<String, Object> clerRwBqk(Map<String,Object> params, User user){
        RecordSet re=new RecordSet();
        boolean flag=true;
        String mess="";
        Map<String, Object> apidatas = new HashMap<String, Object>();
        List<Object> list=new ArrayList<Object>();
        String rwid=Util.null2String(params.get("rwid")) ;//任务ID
        if(rwid.endsWith(",")){
            rwid=rwid.substring(0,rwid.length()-1);
        }
        log.writeLog("rwid--->"+rwid);

        //检验是否存在
        Uf_bqk uf_bqk=new Uf_bqk();
        if(!"".equals(rwid)){
            String sql="update uf_jcdcrw set rwbq='' where id in ("+rwid+")";
            re.execute(sql);
        }
        apidatas.put("flag",true);
        apidatas.put("mess",mess);
        return apidatas;
    }
}
